home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / cpkocx17 / briscola.bas < prev    next >
Encoding:
BASIC Source File  |  1998-07-17  |  36.2 KB  |  1,460 lines

  1. Attribute VB_Name = "Briscola"
  2. Option Explicit
  3.                                     
  4. '
  5. ' Application Program Information and related constants
  6. '
  7. Global Const App_Version$ = "Version 1.6, 10 July 1998"
  8. Global Const App_Copyright$ = "Copyright ⌐ 1996-1998 Andy Zanna"
  9. Global Const App_Author$ = "Written by A.Zanna"
  10.  
  11. Global Const SEC_GLOBAL = "Briscola"
  12. Global Const KEY_WORKDIR = "WorkDir"
  13.  
  14. Global Const App_DDEShare = "Briscola$"
  15. Global Const App_FileType = "Briscola Game"
  16. Global Const App_FileExt = "bri"
  17. Global Const App_ClipFormat = 1             ' Text. We could check for more than one format...
  18.  
  19. Global Const App_Profile = "Briscola.INI"
  20.  
  21. Global App_Debug
  22.  
  23. Global Game_OtherPC As String               ' name of other workstation
  24. Global Game_OtherPlayer As String           ' name of other guy
  25.  
  26. Global Game_InProgress As Integer           ' Flag a game is in progress
  27. Global Game_FileName$                       ' Current file name
  28. Global Game_Mode As Integer                 ' normal network or demo
  29.  
  30. Global Game_BriscolaSuit  As Integer
  31.  
  32. Global Hand_Number As Integer               ' # of hand being played
  33. Global Hand_Winner As Integer               ' winner of this hand (<> 0 flags Hand_Next() needs running)
  34. Global Hand_CardPlayer1  As Integer         ' cards played by player 1 and 2
  35. Global Hand_CardPlayer2  As Integer
  36. Global Hand_PlayerTurn  As Integer          ' # of player who's to deal or play
  37.  
  38. Global Player1_Score  As Integer            ' score for player 1
  39. Global Player1_AutoPlay As Integer          ' autoplay enabled for player 1
  40. Global Player1_Name As String               ' cached player Name
  41.  
  42. Global Player2_AutoPlay As Integer          ' autoplay enabled for player 2
  43. Global Player2_Score  As Integer            ' score for player 2
  44. Global Player2_Name As String               ' cached player Name
  45.  
  46. Global Const Game_NoFileName$ = "Unnamed"   ' Used when no file active
  47.  
  48. Global Const MUST_PLAY = "'s turn"
  49. Global Const WINS_HAND = " wins hand"
  50. Global Const WINS_GAME = " wins game! "
  51. Global Const GAME_IS_DRAW = "Game is a draw"
  52. Global Const NOT_YOUR_TURN = ", it's not your turn!"
  53. Global Const NOT_YOUR_CARDS = ", those are not your cards!"
  54. Global Const NOT_NOW = ", you can't do that just now"
  55.  
  56. Global Const MSG_MODE_NORMAL = "Mode: Normal"
  57. Global Const MSG_MODE_NETWORK = "Mode: Network"
  58. Global Const MSG_MODE_DEMO = "Mode: Demo"
  59.  
  60. Global Const MODE_NORMAL = 1
  61. Global Const MODE_NETWORK = 2
  62. Global Const MODE_DEMO = 3
  63.  
  64.  
  65.  
  66. '
  67. ' In network mode, only 1 player (the last deals or stashes cards),
  68. ' the other party will receive cards via DDE. This prevents
  69. ' conflicting updates via cross DDE
  70. '
  71. Function Game_IsDealer() As Integer
  72.     
  73.     Game_IsDealer = True
  74.     
  75.     If Game_Mode = MODE_NETWORK And Hand_PlayerTurn <> 1 Then
  76.         Game_IsDealer = False
  77.     End If
  78.     
  79.     If App_Debug Then
  80.         If Game_IsDealer Then
  81.             Trace "Game_IsDealer: yes"
  82.         Else
  83.             Trace "Game_IsDealer: no, waiting for network peer"
  84.         End If
  85.     End If
  86.  
  87. End Function
  88.  
  89. Sub Game_Open(fname As String)
  90.     If App_Debug Then Trace "Game_Open"
  91.     
  92. #If Win16 Then
  93.     Game_OpenAsBin fname
  94. #Else
  95.     Game_OpenAsText fname
  96. #End If
  97.  
  98.     Game_FileName$ = fname
  99.     Form_SetTitle Game
  100.     Game_ShowScore
  101.     Game_Pause True
  102.     Game_InProgress = True
  103.     Game.Player2Name = Player2_Name
  104.     Game.Player1Name = Player1_Name
  105.  
  106.     ' we will never restore network connection
  107.     ' so default to let computer handle player 2
  108.     Player2_AutoPlay = True
  109.     
  110.     ' saved in demo mode?
  111.     If Player1_AutoPlay Then
  112.         Game.OptPeek.Checked = 1
  113.         Game.Player2.StackFacing = CARDS_FACING_UP
  114.     End If
  115.     
  116. End Sub
  117.  
  118. Sub Game_OpenAsText(fname As String)
  119.     Dim s$
  120.  
  121.     If App_Debug Then Trace "Game_OpenAsText"
  122.     On Error GoTo open_error
  123.  
  124.     Open fname For Input As #1
  125.  
  126.     On Error GoTo open_done
  127.     
  128.     Input #1, Hand_Number
  129.     Input #1, Hand_CardPlayer1
  130.     Input #1, Hand_CardPlayer2
  131.     Input #1, Hand_PlayerTurn
  132.     Input #1, Hand_Winner
  133.     Input #1, Game_BriscolaSuit
  134.  
  135.     Input #1, Player1_Score
  136.     Input #1, Player1_AutoPlay
  137.     Input #1, Player1_Name
  138.  
  139.     Input #1, Player2_AutoPlay
  140.     Input #1, Player2_Score
  141.     Input #1, Player2_Name
  142.     
  143.     Input #1, s$
  144.     Game.Player1 = s$
  145.     Input #1, s$
  146.     Game.Player2 = s$
  147.     Input #1, s$
  148.     Game.Stack1 = s$
  149.     Input #1, s$
  150.     Game.Stack2 = s$
  151.     Input #1, s$
  152.     Game.Briscola = s$
  153.     Input #1, s$
  154.     Game.OnTable = s$
  155.     Input #1, s$
  156.     Game.Deck = s$
  157.         
  158. open_done:
  159.  
  160.     Close #1
  161.     Exit Sub
  162.  
  163. open_error:
  164.     ReportError "Can't open File" & Chr$(10) & "'" & fname & "'"
  165.     Exit Sub
  166.  
  167. End Sub
  168.  
  169. Sub Game_Save(fname As String)
  170.     If App_Debug Then Trace "Game_Save"
  171.  
  172. #If Win16 Then
  173.     Game_SaveAsBin fname
  174. #Else
  175.     Game_SaveAsText fname
  176. #End If
  177.  
  178.     Game_FileName = fname
  179.     Form_SetTitle Game
  180.  
  181. End Sub
  182.  
  183. Sub Game_SaveAsText(fname As String)
  184.  
  185.     Dim s$
  186.     If App_Debug Then Trace "Game_SaveAsText"
  187.     On Error GoTo save_error
  188.  
  189.     Open fname For Output As #1
  190.     
  191.     On Error GoTo write_error
  192.     
  193.     Print #1, Hand_Number
  194.     Print #1, Hand_CardPlayer1
  195.     Print #1, Hand_CardPlayer2
  196.     Print #1, Hand_PlayerTurn
  197.     Print #1, Hand_Winner
  198.     
  199.     Print #1, Game_BriscolaSuit
  200.  
  201.     Print #1, Player1_Score
  202.     Print #1, Player1_AutoPlay
  203.     Print #1, Player1_Name
  204.  
  205.     Print #1, Player2_AutoPlay
  206.     Print #1, Player2_Score
  207.     Print #1, Player2_Name
  208.  
  209.     s$ = Game.Player1
  210.     Print #1, s$
  211.     s$ = Game.Player2
  212.     Print #1, s$
  213.     s$ = Game.Stack1
  214.     Print #1, s$
  215.     s$ = Game.Stack2
  216.     Print #1, s$
  217.     s$ = Game.Briscola
  218.     Print #1, s$
  219.     s$ = Game.OnTable
  220.     Print #1, s$
  221.     s$ = Game.Deck
  222.     Print #1, s$
  223.  
  224. write_error:
  225.     Close #1
  226.     
  227.  
  228. save_error:
  229.     Exit Sub
  230.  
  231. End Sub
  232.  
  233. '
  234. ' Report whether a player is allowed to play
  235. '
  236. Function Hand_CanPlay(pl%) As Integer
  237.  
  238.     Hand_CanPlay = False   ' disallow by default
  239.     
  240.     If Not Game_InProgress Then Exit Function
  241.    
  242.     If pl% = 1 Then
  243.         If Hand_CardPlayer1 <> CARD_EMPTY Then Exit Function  ' has already played
  244.         If Hand_PlayerTurn <> 1 Then Exit Function           ' not his turn
  245.         
  246.         ' this checks whether he is still waiting for cards to be dealt
  247.         If Game.Player1.NumCards < 3 And Game.Deck.NumCards > 0 Then Exit Function
  248.     Else
  249.         If Hand_CardPlayer2 <> CARD_EMPTY Then Exit Function  ' has already played
  250.         If Hand_PlayerTurn = 1 Then Exit Function          ' not his turn
  251.     
  252.         ' this checks whether he is still waiting for cards to be dealt
  253.         If Game.Player2.NumCards < 3 And Game.Deck.NumCards > 0 Then Exit Function
  254.     End If
  255.     
  256.     Hand_CanPlay = True
  257.  
  258. End Function
  259.  
  260. '
  261. ' Clear 'played cards', allowing players to play again
  262. '
  263. Sub Hand_Clear()
  264.     Trace "Hand_Clear"
  265.     
  266.     Hand_CardPlayer1 = CARD_EMPTY
  267.     Hand_CardPlayer2 = CARD_EMPTY
  268. End Sub
  269.  
  270. Sub Hand_DealCard(dest As Cardpack)
  271.     Dim x%, y%
  272.     
  273.     If App_Debug Then Trace "Hand_DealCard"
  274.     
  275.     ' check if dealing last hand
  276.     If Game.Deck.NumCards > 0 Then
  277.         Game.MoveCard Game.Deck, Game.Deck.NumCards - 1, dest
  278.     Else
  279.         Game.MoveCard Game.Briscola, 0, dest
  280.     End If
  281.         
  282.     If App_Debug Then Trace "Hand_DealCard: dealt " & CardName$(dest.Card(dest.NumCards - 1))
  283.         
  284. End Sub
  285.  
  286. Sub Hand_StashCard(dest As Cardpack)
  287.     If App_Debug Then Trace "Hand_StashCard"
  288.     
  289.     Game.MoveCard Game.OnTable, Game.OnTable.NumCards - 1, dest
  290. End Sub
  291.  
  292. Sub Hand_PlayCard(src As Cardpack, idx%)
  293.     
  294.     If App_Debug Then Trace "Hand_PlayCard"
  295.     Game_Msg "Player plays the " & CardName$(src.Card(idx%))
  296.     Game.MoveCard src, idx%, Game.OnTable
  297. End Sub
  298.  
  299.  
  300. Sub Main()
  301.     If App_Debug Then Trace "Main"
  302.  
  303.     App_Init Game
  304.     
  305.     
  306.     AboutForm.Show 1
  307.     Game.Show
  308.     If Not Game_Options() Then End
  309.  
  310. End Sub
  311.  
  312. Sub Game_Accept(CmdStr As String, Cancel As Integer)
  313.     
  314.     Dim r%, s$
  315.     If App_Debug Then Trace "Game_Accept"
  316.  
  317.     r% = InStr(CmdStr, ",")
  318.     
  319.     Game_OtherPC = Left$(CmdStr, r% - 1)
  320.     Game_OtherPlayer = Mid$(CmdStr, r% + 1)
  321.  
  322.     s$ = Game_OtherPlayer & " challenges you from " & Game_OtherPC
  323.     s$ = s$ & Chr$(10) & "Do you accept the challenge?"
  324.  
  325.     If MsgBox(s$, MB_YESNO + MB_ICONQUESTION) = IDNO Then
  326.         Cancel = True
  327.     Else
  328.         Game_ModeNetwork
  329.         Game.GameTimer.Enabled = True    ' will connect back ASAP.
  330.         Cancel = False              ' by default, cancel = True
  331.     End If
  332.  
  333. End Sub
  334.  
  335.  
  336.  
  337. '
  338. ' Find card that's higher than given card (lowest first).
  339. ' same suit or any, depending on pattern
  340. '
  341. ' retuns card index
  342. '
  343. Function CardPack_FindHigherThan(cs As Cardpack, pat%) As Integer
  344.     Dim s%, v%, i%, c%
  345.  
  346.     c% = 0
  347.     s% = CardSuit(pat%)
  348.     v% = CardValue(pat%)
  349.  
  350.     For i% = v% + 1 To KING
  351.         c% = cs.Find(s% + i%)
  352.         If c% <> CARD_NONE Then Exit For
  353.     Next i%
  354.  
  355.     CardPack_FindHigherThan = c%
  356.  
  357. End Function
  358.  
  359. '
  360. ' Find card that's lower than given card (highest first).
  361. ' same suit or any, depending on pattern
  362. '
  363. ' retuns card index
  364. '
  365. Function CardPack_FindLowerThan(cs As Cardpack, pat%) As Integer
  366.         Dim s%, v%, i%, c%
  367.  
  368.         c% = 0
  369.         s% = CardSuit(pat%)
  370.         v% = CardValue(pat%)
  371.  
  372.         For i% = v% - 1 To ACE Step -1
  373.             c% = cs.Find(s% + i%)
  374.             If c% <> CARD_NONE Then Exit For
  375.         Next i%
  376.  
  377.         CardPack_FindLowerThan = c%
  378.  
  379. End Function
  380.  
  381. Function Game_AllowAbort()
  382.     
  383.     Dim response As Integer
  384.     Dim Msg As String
  385.  
  386.     response = IDNO
  387.     Game_AllowAbort = True
  388.     If App_Debug Then Trace "Game_AllowAbort"
  389.  
  390.     If Game_InProgress = True Then
  391.         Msg = "A game is in progress" & Chr$(10)
  392.         Msg = Msg & "Save it before continuing?"
  393.         response = MsgBox(Msg, MB_YESNOCANCEL + MB_ICONQUESTION, App.Title)
  394.     End If
  395.  
  396.     Select Case response
  397.         Case IDYES
  398.             Game_Save Game_FileName$
  399.         Case IDNO
  400.         Case IDCANCEL
  401.             Game_AllowAbort = False
  402.     End Select
  403. End Function
  404.  
  405. '
  406. ' Game plays for a player if:
  407. ' - it's this player's turn
  408. ' - autoplay is enabled for this player
  409. ' - 3 cards have been given to this player (or it's last hand)
  410. ' Will only do one player per run
  411. '
  412. Sub Game_AutoPlay()
  413.     
  414.     If App_Debug Then Trace "Game_AutoPlay"
  415.     
  416.     ' up to player one ?
  417.     If Hand_CanPlay(1) And Player1_AutoPlay Then
  418.         Robot_PlayCard Game.Player1
  419.         Exit Sub
  420.     End If
  421.  
  422.     ' up to player two
  423.     If Hand_CanPlay(2) And Player2_AutoPlay Then
  424.         Robot_PlayCard Game.Player2
  425.         Exit Sub
  426.     End If
  427. End Sub
  428.  
  429. Function Game_CalcScore(Deck As Cardpack) As Integer
  430.     Dim Score%
  431.     
  432.     If App_Debug Then Trace "Game_CalcScore"
  433.  
  434.     ' aces value = 11
  435.     Score% = 11 * Deck.Count(ACE)
  436.     
  437.     ' 3 value = 10
  438.     Score% = Score% + 10 * Deck.Count(3)
  439.  
  440.     ' king, queen, jack = 3,2,1
  441.     Score% = Score% + 4 * Deck.Count(KING)
  442.     Score% = Score% + 3 * Deck.Count(QUEEN)
  443.     Score% = Score% + 2 * Deck.Count(JACK)
  444.  
  445.     Game_CalcScore = Score%
  446.  
  447. End Function
  448.  
  449. Sub Game_Clear()
  450.     If App_Debug Then Trace "Game_Clear"
  451.     
  452.     Game_InProgress = False
  453.     Game.GameTimer.Enabled = False
  454.  
  455.     Game_FileName$ = Game_NoFileName$
  456.  
  457.     Player1_Score = 0
  458.     Player2_Score = 0
  459.     
  460.     Game_ShowScore
  461.  
  462. End Sub
  463.  
  464. Function Game_Connect(OtherPC As String, IsReply As Integer) As Integer
  465.     Dim s$
  466.  
  467.     If App_Debug Then Trace "Game_Connect"
  468.     
  469.     On Error GoTo net_err
  470.  
  471.     Game_Connect = False
  472.  
  473.     'If OtherPC = "" Then Exit Function
  474.     'Debug.Print "----- Connecting -----"
  475.     
  476.     ' give time to other replay to accept challenge (20s)
  477.     If IsReply Then
  478.         Game.Player2Name.LinkTimeout = 50
  479.     Else
  480.         Game.Player2Name.LinkTimeout = 200
  481.     End If
  482.  
  483.     ' This is used to get a link on which a challenge is sent
  484.     NDDEConnect Game.Player2Name, OtherPC, App_DDEShare, "Player1Name"
  485.  
  486.     
  487.     If Not IsReply Then
  488.         ' if we're connecting (NOT replying to a connection)
  489.         ' send a challenge, with our computer name as a command
  490.         s$ = NetHostName$() & "," & Player1_Name
  491.         Game_NetCommand "C", s$
  492.     End If
  493.  
  494.     ' these are cross-linked
  495.     NDDEConnect Game.Player1, OtherPC, App_DDEShare, "Player2"
  496.     NDDEConnect Game.Player2, OtherPC, App_DDEShare, "Player1"
  497.  
  498.     NDDEConnect Game.Stack1, OtherPC, App_DDEShare, "Stack2"
  499.     NDDEConnect Game.Stack2, OtherPC, App_DDEShare, "Stack1"
  500.     
  501.     NDDEConnect Game.OnTable, OtherPC, App_DDEShare, "OnTable"
  502.     NDDEConnect Game.Deck, OtherPC, App_DDEShare, "Deck"
  503.     NDDEConnect Game.Briscola, OtherPC, App_DDEShare, "Briscola"
  504.     
  505.     Game_Connect = True
  506.     'Debug.Print "----- Connected OK -----"
  507.  
  508.     Exit Function
  509.  
  510. net_err:
  511.     
  512.     Game_Disconnect
  513.     MsgBox "Failed Connecting to " & OtherPC & Chr$(10) & " (" & Error$ & ")"
  514.     Exit Function
  515.  
  516. End Function
  517.  
  518. Sub Game_ConnectBack()
  519.     If App_Debug Then Trace "Game_ConnectBack"
  520.     
  521.     If Game_Connect(Game_OtherPC, True) Then
  522.         Hand_SetNextPlayer 1
  523.         Game_Start
  524.     Else
  525.         Game_Disconnect
  526.         Game_ModeNormal
  527.     End If
  528.  
  529. End Sub
  530.  
  531. '
  532. ' Returns # of cards already played matching pattern
  533. ' for strategy support.
  534. '
  535. ' Simulates memory by peeking into the 2 players
  536. ' 'captured cards' stacks
  537. '
  538. Function Game_CountPlayed(c%) As Integer
  539.     
  540.     If App_Debug Then Trace "Game_CountPlayed"
  541.  
  542.     Dim n%
  543.  
  544.     n% = Game.Stack1.Count(c%)
  545.     n% = n% + Game.Stack2.Count(c%)
  546.  
  547.     Game_CountPlayed = c%
  548.  
  549. End Function
  550.  
  551. Sub Game_Disconnect()
  552.     If App_Debug Then Trace "Game_Disconnect"
  553.  
  554.     Game.Player2Name.LinkMode = 0
  555.  
  556.     Game.Player1.LinkMode = 0
  557.     Game.Player2.LinkMode = 0
  558.  
  559.     Game.Stack1.LinkMode = 0
  560.     Game.Stack2.LinkMode = 0
  561.  
  562.     Game.OnTable.LinkMode = 0
  563.     Game.Deck.LinkMode = 0
  564.     Game.Briscola.LinkMode = 0
  565.  
  566. End Sub
  567.  
  568. Sub Game_Finish(fAbort As Integer)
  569.     If App_Debug Then Trace "Game_Finish"
  570.     
  571.     If Game_InProgress Then
  572.         
  573.         If fAbort Then
  574.             If Not Game_AllowAbort() Then Exit Sub
  575.  
  576.             If Game_Mode = MODE_NETWORK Then
  577.                 Game_Disconnect
  578.             End If
  579.             ' Game_ModeNormal
  580.         Else
  581.             If Player1_Score > Player2_Score Then
  582.                 MsgBox Game_PlayerName(1) & WINS_GAME & Player1_Score & "-" & Player2_Score
  583.             Else
  584.                 If Player1_Score < Player2_Score Then
  585.                     MsgBox Game_PlayerName(2) & WINS_GAME & Player2_Score & "-" & Player1_Score
  586.                 Else
  587.                     MsgBox GAME_IS_DRAW
  588.                 End If
  589.             End If
  590.         End If
  591.         
  592.         Game.GameTimer.Enabled = False
  593.         Game_InProgress = False
  594.  
  595.     End If
  596.     
  597.     Game.ModeStop
  598.     
  599. End Sub
  600.  
  601. Sub Game_GiveHint()
  602.     Dim idx%
  603.  
  604.     If App_Debug Then Trace "Game_GiveHint"
  605.     
  606.     If Hand_PlayerTurn = 1 Then
  607.         idx% = Robot_ThinkCard(Game.Player1)
  608.  
  609.         If idx% <> CARD_NONE Then
  610.             Game.Player1.Selected(idx%) = True
  611.             Game.MessageView = "I suggest you play the " & CardName$(Game.Player1.Card(idx%))
  612.         End If
  613.     Else
  614.         Game.MessageView = Game_PlayerName(1) & NOT_YOUR_TURN
  615.     End If
  616.  
  617. End Sub
  618. Sub Game_Listen()
  619.     Dim r%
  620.  
  621.     If App_Debug Then Trace "Game_Listen"
  622.     r% = NDDEListen(App_DDEShare, "BRISCOLA", "Table")
  623.  
  624. End Sub
  625.  
  626. Sub Game_ModeDemo()
  627.     If App_Debug Then Trace "Game_ModeDemo"
  628.     
  629.     Player1_Name = "Computer 1"
  630.     Player2_Name = "Computer 2"
  631.            
  632.     Player1_AutoPlay = True
  633.     Player2_AutoPlay = True
  634.  
  635.     Game.OptPeek.Checked = 1
  636.     Game.Player2.StackFacing = CARDS_FACING_UP
  637.     
  638.     Game.Mode = MSG_MODE_DEMO
  639.     Game_Mode = MODE_DEMO
  640.     
  641. End Sub
  642.  
  643. Sub Game_ModeNetwork()
  644.     
  645.     If App_Debug Then Trace "Game_ModeNetwork"
  646.    
  647.     If App_Debug Then
  648.         Player1_AutoPlay = True
  649.     Else
  650.         Player1_AutoPlay = False
  651.     End If
  652.  
  653.     Player2_AutoPlay = False
  654.  
  655.     If App_Debug Then
  656.         Game.OptPeek.Checked = 1
  657.         Game.Player2.StackFacing = CARDS_FACING_UP
  658.         Game.GameTimer.Interval = 100   ' faster than normal
  659.     Else
  660.         Game.OptPeek.Checked = 0
  661.         Game.Player2.StackFacing = CARDS_FACING_DOWN
  662.     End If
  663.  
  664.     Game_Mode = MODE_NETWORK
  665.     Game.Mode = MSG_MODE_NETWORK
  666.     
  667. End Sub
  668.  
  669. Sub Game_ModeNormal()
  670.        
  671.     If App_Debug Then Trace "Game_ModeNormal"
  672.     Player2_Name = "Computer"
  673.    
  674.     Player1_AutoPlay = False
  675.     Player2_AutoPlay = True
  676.  
  677.     Game.OptPeek.Checked = 0
  678.     Game.Player2.StackFacing = CARDS_FACING_DOWN
  679.  
  680.     Game.Mode = MSG_MODE_NORMAL
  681.     Game_Mode = MODE_NORMAL
  682.  
  683. End Sub
  684.  
  685. Sub Game_Msg(Msg$)
  686.     Game.MessageView.Caption = Msg$
  687.     Game.MessageView.Refresh
  688. End Sub
  689.  
  690. '
  691. ' Manda comando al partner, con parametri
  692. '
  693. Sub Game_NetCommand(c$, p$)
  694.     If App_Debug Then Trace "Game_NetCommand"
  695.     
  696.     Game.Player2Name.LinkExecute c$ & p$
  697. End Sub
  698.  
  699. Sub Game_New()
  700.     
  701.     If App_Debug Then Trace "Game_New"
  702.     If Game_AllowAbort() = True Then
  703.         
  704.         Game_Clear
  705.         Game_Start
  706.         Table_Clear
  707.         Hand_DealFirst
  708.         
  709.     End If
  710.  
  711.     If Game_Mode = MODE_NETWORK Then Game_NetCommand "R", ""
  712.  
  713. End Sub
  714.  
  715. ' Switch sides if 1st card was played
  716. Sub Hand_SwitchPlayer()
  717.     
  718.     If App_Debug Then Trace "Hand_SwitchPlayer"
  719.     
  720.     If Game.OnTable.NumCards = 1 Then
  721.         
  722.         ' make a note of who played, so we know he can't play
  723.         ' until next hand has been dealt
  724.         
  725.         If Hand_PlayerTurn = 1 Then
  726.             Hand_CardPlayer1 = Game.OnTable.Card(0)
  727.         Else
  728.             Hand_CardPlayer2 = Game.OnTable.Card(0)
  729.         End If
  730.         
  731.         Hand_SetNextPlayer (Hand_PlayerTurn + 1)
  732.     End If
  733. End Sub
  734.  
  735. Sub Hand_SetNextPlayer(pl%)
  736.     If App_Debug Then Trace "Hand_SetNextPlayer: " & (pl% Mod 2)
  737.     
  738.     Hand_PlayerTurn = pl% Mod 2
  739.     Game.MessageView = Game_PlayerName(Hand_PlayerTurn) & MUST_PLAY
  740.  
  741. End Sub
  742.  
  743. Sub Game_OpenAsBin(fname As String)
  744.     If App_Debug Then Trace "Game_OpenAsBin"
  745.     
  746.     Dim s$
  747.  
  748.     On Error GoTo open_error
  749.  
  750.     Open fname For Random As #1
  751.  
  752.     On Error GoTo open_done
  753.     
  754.     Get #1, , Hand_Number
  755.     Get #1, , Hand_CardPlayer1
  756.     Get #1, , Hand_CardPlayer2
  757.     Get #1, , Hand_PlayerTurn
  758.     Get #1, , Hand_Winner
  759.     Get #1, , Game_BriscolaSuit
  760.  
  761.     Get #1, , Player1_Score
  762.     Get #1, , Player1_AutoPlay
  763.     Get #1, , Player1_Name
  764.  
  765.     Get #1, , Player2_AutoPlay
  766.     Get #1, , Player2_Score
  767.     Get #1, , Player2_Name
  768.     
  769.     Get #1, , s$
  770.     Game.Player1 = s$
  771.     Get #1, , s$
  772.     Game.Player2 = s$
  773.     Get #1, , s$
  774.     Game.Stack1 = s$
  775.     Get #1, , s$
  776.     Game.Stack2 = s$
  777.     Get #1, , s$
  778.     Game.Briscola = s$
  779.     Get #1, , s$
  780.     Game.OnTable = s$
  781.     Get #1, , s$
  782.     Game.Deck = s$
  783.     
  784.     
  785.     
  786. open_done:
  787.  
  788.     Close #1
  789.     Exit Sub
  790.  
  791. open_error:
  792.     ReportError "Can't open File" & Chr$(10) & "'" & fname & "'"
  793.     Exit Sub
  794. End Sub
  795.  
  796. Function Game_Options() As Integer
  797.     Dim New_mode As Integer
  798.     
  799.     If App_Debug Then Trace "Game_Options"
  800.     Options.Show 1
  801.     
  802.     If Options.Tag = "OK" Then
  803.         Player1_Name = Options.NameBox
  804.     
  805.         If Options.OptVsNetwork.Value Then
  806.             New_mode = MODE_NETWORK
  807.             Else
  808.                 If Options.OptDemo.Value Then
  809.                     New_mode = MODE_DEMO
  810.                 Else
  811.                     New_mode = MODE_NORMAL
  812.             End If
  813.         End If
  814.     
  815.         ' record player name, just in case.
  816.         Profile_WriteString SEC_GLOBAL, "PlayerName", Player1_Name
  817.  
  818.         ' if different, change mode and start new game
  819.         
  820.         If New_mode <> Game_Mode Then
  821.             Select Case New_mode
  822.                 Case MODE_NETWORK
  823.                     
  824.                     If Game_Connect(NetBrowseHost$(), False) Then
  825.                         Game_ModeNetwork
  826.                         Hand_SetNextPlayer 2  ' let other player start
  827.                     End If
  828.                 
  829.                 Case MODE_DEMO
  830.                     Game_ModeDemo
  831.                 
  832.                 Case Else
  833.                     Game_ModeNormal
  834.             End Select
  835.             
  836.         End If
  837.  
  838.         Game_Options = True
  839.         Game_Finish True
  840.         Game_New
  841.     Else
  842.         Game_Options = False
  843.     End If
  844.  
  845. End Function
  846.  
  847. Sub Game_Pause(paused%)
  848.     If App_Debug Then Trace "Game_Pause"
  849.     
  850.     If paused% Then
  851.         Game.GameTimer.Enabled = False
  852.         Game_Msg "Paused"
  853.         Game.ModePause
  854.     Else
  855.         Game.GameTimer.Enabled = True
  856.         Game_Msg "Resumed"
  857.         Game.ModeRun
  858.     End If
  859.     
  860. End Sub
  861.  
  862. '
  863. ' Implements simple player game strategy
  864. ' Retuns index of next card this player should play
  865. '
  866. Function Robot_ThinkCard(pl As Cardpack) As Integer
  867.     
  868.     Dim cidx%, t_val%, t_suit%, i%
  869.  
  870.     If App_Debug Then Trace "Robot_ThinkCard"
  871.     cidx% = CARD_NONE
  872.        
  873.     ' must play against table
  874.     If Game.OnTable.NumCards = 1 Then
  875.         t_val% = Game.OnTable.Value(0)
  876.         t_suit% = Game.OnTable.Suit(0)
  877.         
  878.         ' no points on the table. Take it only if
  879.         ' we can make some points (jack, queen)
  880.         If t_val% = 2 Or (t_val% > 3 And t_val% < JACK) Then
  881.             
  882.             cidx% = pl.Find(JACK + t_suit%)
  883.             If cidx% <> CARD_NONE Then GoTo Chosen
  884.         
  885.             cidx% = pl.Find(QUEEN + t_suit%)
  886.             If cidx% <> CARD_NONE Then GoTo Chosen
  887.         
  888.         End If
  889.  
  890.         ' small points on the table. Try to take it.
  891.         If t_val% >= JACK And t_val% < KING Then
  892.             
  893.             cidx% = CardPack_FindHigherThan(pl, t_val% + t_suit%)
  894.             If cidx% <> CARD_NONE Then GoTo Chosen
  895.  
  896.             ' may also want to use 3 or ACE if deck is running low
  897.             If Game.Deck.NumCards < 20 Then
  898.                 cidx% = pl.Find(3 + t_suit%)
  899.                 If cidx% <> CARD_NONE Then GoTo Chosen
  900.             
  901.                 cidx% = pl.Find(ACE + t_suit%)
  902.                 If cidx% <> CARD_NONE Then GoTo Chosen
  903.             End If
  904.         End If
  905.         
  906.         ' always take king, try with 3 or ace
  907.         If t_val% = KING Then
  908.             cidx% = pl.Find(3 + t_suit%)
  909.             If cidx% <> CARD_NONE Then GoTo Chosen
  910.             
  911.             cidx% = pl.Find(ACE + t_suit%)
  912.             If cidx% <> CARD_NONE Then GoTo Chosen
  913.         End If
  914.     
  915.         ' always take 3, can only be taken by ace
  916.         If t_val% = 3 Then
  917.             cidx% = pl.Find(ACE + t_suit%)
  918.             If cidx% <> CARD_NONE Then GoTo Chosen
  919.         End If
  920.  
  921.  
  922.         ' we want that 3 or ace, but can't beat it with the same suit
  923.         ' try taking it with a briscola, lowest first (3 and ace last)
  924.         If t_val% = 3 Or t_val% = ACE Then
  925.             cidx% = pl.Find(2 + t_suit%)
  926.             If cidx% <> CARD_NONE Then GoTo Chosen
  927.             
  928.             cidx% = CardPack_FindHigherThan(pl, 3 + Game_BriscolaSuit%)
  929.             If cidx% <> CARD_NONE Then GoTo Chosen
  930.  
  931.             cidx% = pl.Find(3 + Game_BriscolaSuit%)
  932.             If cidx% <> CARD_NONE Then GoTo Chosen
  933.         
  934.             cidx% = pl.Find(ACE + Game_BriscolaSuit%)
  935.             If cidx% <> CARD_NONE Then GoTo Chosen
  936.         
  937.         End If
  938.  
  939.         ' card on table is nil points, but maybe we can make points
  940.         ' taking it with a higher card of ours (not a briscola)
  941.         
  942.         If t_suit% <> Game_BriscolaSuit Then
  943.             ' use ace only if 3 is gone
  944.             If Game_CountPlayed(3 + t_suit%) > 0 Then
  945.                 cidx% = pl.Find(ACE + t_suit%)
  946.                 If cidx% <> CARD_NONE Then GoTo Chosen
  947.             End If
  948.     
  949.             ' use 3 only if king is gone
  950.             If Game_CountPlayed(KING + t_suit%) > 0 Then
  951.                 cidx% = pl.Find(3 + t_suit%)
  952.                 If cidx% <> CARD_NONE Then GoTo Chosen
  953.             End If
  954.                 
  955.             ' use king only if queen is gone
  956.             If Game_CountPlayed(QUEEN + t_suit%) > 0 Then
  957.                 cidx% = pl.Find(KING + t_suit%)
  958.                 If cidx% <> CARD_NONE Then GoTo Chosen
  959.             End If
  960.             
  961.             ' use queen only if jack is gone
  962.             If Game_CountPlayed(JACK + t_suit%) > 0 Then
  963.                 cidx% = pl.Find(QUEEN + t_suit%)
  964.                 If cidx% <> CARD_NONE Then GoTo Chosen
  965.             End If
  966.     
  967.             cidx% = pl.Find(JACK + t_suit%)
  968.             If cidx% <> CARD_NONE Then GoTo Chosen
  969.         End If
  970.  
  971.     End If
  972.  
  973.     ' if we get here, we are either playing 1st
  974.     ' or we're not interested in the card that's on the table
  975.  
  976.     ' find lowest card in hand that's not a briscola
  977.     For i% = HEARTS To SPADES Step ONE_SUIT
  978.         
  979.         If i% <> Game_BriscolaSuit% Then
  980.             ' see if we have a 2
  981.             cidx% = pl.Find(i% + 2)
  982.             If cidx% <> CARD_NONE Then GoTo Chosen
  983.             
  984.             ' or any lowest card that's not points
  985.             cidx% = CardPack_FindHigherThan(pl, i% + 3)
  986.             If cidx% <> CARD_NONE Then
  987.                 If pl.Value(cidx%) < JACK Then GoTo Chosen
  988.             End If
  989.         End If
  990.     Next i%
  991.  
  992.     
  993.     ' Next, see if we can play a briscola that's not points
  994.     ' see if we have a 2
  995.     cidx% = pl.Find(Game_BriscolaSuit% + 2)
  996.     If cidx% <> CARD_NONE Then GoTo Chosen
  997.     
  998.     ' or any lowest briscola that's also not points
  999.     cidx% = CardPack_FindHigherThan(pl, Game_BriscolaSuit% + 3)
  1000.     If cidx% <> CARD_NONE Then
  1001.         If pl.Value(cidx%) < JACK Then GoTo Chosen
  1002.     End If
  1003.     
  1004.  
  1005.     ' Next, see if we have to give in small points (not briscola)
  1006.     For i% = HEARTS To SPADES Step ONE_SUIT
  1007.         
  1008.         If i% <> Game_BriscolaSuit% Then
  1009.         ' look for Jack, Queen, King
  1010.             cidx% = CardPack_FindHigherThan(pl, i% + 10)
  1011.             If cidx% <> CARD_NONE Then GoTo Chosen
  1012.         End If
  1013.     Next i%
  1014.     
  1015.  
  1016.     ' Next, see if we have to play a briscola that's small points
  1017.     ' look for Jack, Queen, King
  1018.     cidx% = CardPack_FindHigherThan(pl, Game_BriscolaSuit% + 10)
  1019.     If cidx% <> CARD_NONE Then GoTo Chosen
  1020.  
  1021.     
  1022.     ' Next, see if we have to play a briscola that's BIG points
  1023.     cidx% = pl.Find(Game_BriscolaSuit% + 3)
  1024.     If cidx% <> CARD_NONE Then GoTo Chosen
  1025.  
  1026.     cidx% = pl.Find(Game_BriscolaSuit% + ACE)
  1027.     If cidx% <> CARD_NONE Then GoTo Chosen
  1028.  
  1029.  
  1030.     ' Last, see if we have to give in BIG points
  1031.     For i% = HEARTS To SPADES Step ONE_SUIT
  1032.         
  1033.         If i% <> Game_BriscolaSuit% Then
  1034.             cidx% = pl.Find(i% + 3)
  1035.             If cidx% <> CARD_NONE Then GoTo Chosen
  1036.         
  1037.             cidx% = pl.Find(i% + ACE)
  1038.             If cidx% <> CARD_NONE Then GoTo Chosen
  1039.         End If
  1040.     Next i%
  1041.     
  1042.     
  1043.     ' We should never get here undecided, however...
  1044.     cidx% = 0  ' 1st card
  1045.  
  1046.  
  1047. Chosen:
  1048.     Robot_ThinkCard = cidx%
  1049.     
  1050. End Function
  1051.  
  1052. Function Game_PlayerName(pl%) As String
  1053.     
  1054.     If pl% = 1 Then
  1055.         Game_PlayerName = Player1_Name
  1056.     Else
  1057.         Game_PlayerName = Player2_Name
  1058.     End If
  1059.  
  1060. End Function
  1061.  
  1062. Sub Game_SaveAsBin(fname As String)
  1063.  
  1064.     Dim s$
  1065.     If App_Debug Then Trace "Game_SaveAsBin"
  1066.     On Error GoTo save_error
  1067.  
  1068.     Open fname For Random As #1
  1069.     
  1070.     On Error GoTo write_error
  1071.     
  1072.     Put #1, , Hand_Number
  1073.     Put #1, , Hand_CardPlayer1
  1074.     Put #1, , Hand_CardPlayer2
  1075.     Put #1, , Hand_PlayerTurn
  1076.     Put #1, , Hand_Winner
  1077.     
  1078.     Put #1, , Game_BriscolaSuit
  1079.  
  1080.     Put #1, , Player1_Score
  1081.     Put #1, , Player1_AutoPlay
  1082.     Put #1, , Player1_Name
  1083.  
  1084.     Put #1, , Player2_AutoPlay
  1085.     Put #1, , Player2_Score
  1086.     Put #1, , Player2_Name
  1087.  
  1088.     s$ = Game.Player1
  1089.     Put #1, , s$
  1090.     s$ = Game.Player2
  1091.     Put #1, , s$
  1092.     s$ = Game.Stack1
  1093.     Put #1, , s$
  1094.     s$ = Game.Stack2
  1095.     Put #1, , s$
  1096.     s$ = Game.Briscola
  1097.     Put #1, , s$
  1098.     s$ = Game.OnTable
  1099.     Put #1, , s$
  1100.     s$ = Game.Deck
  1101.     Put #1, , s$
  1102.  
  1103.     Game_FileName = fname
  1104.     Form_SetTitle Game
  1105.  
  1106. write_error:
  1107.     Close #1
  1108.     
  1109.  
  1110. save_error:
  1111.     Exit Sub
  1112. End Sub
  1113.  
  1114. Sub Game_SetDefaults()
  1115.     If App_Debug Then Trace "Game_SetDefaults"
  1116.     Player2_AutoPlay = True
  1117.     Game.Mode = MSG_MODE_NORMAL
  1118.     Game.MessageView = "Select [New] to start"
  1119. End Sub
  1120.  
  1121. Sub Game_ShowScore()
  1122.     If App_Debug Then Trace "Game_ShowScore"
  1123.     
  1124.     Player1_Score% = Game_CalcScore(Game.Stack1)
  1125.     Player2_Score% = Game_CalcScore(Game.Stack2)
  1126.     
  1127.     Game.Score1 = Player1_Score%
  1128.     Game.Score2 = Player2_Score%
  1129.  
  1130.     Game.Score = "Score: " & Player1_Score% & "-" & Player2_Score%
  1131.  
  1132. End Sub
  1133.  
  1134. Sub Game_Start()
  1135.     If App_Debug Then Trace "Game_Start"
  1136.     Game_InProgress = True
  1137.     Hand_Number = 1
  1138.     TraceClear
  1139.     
  1140.     Game.ModeRun
  1141.     Game.GameTimer.Enabled = True
  1142. End Sub
  1143.  
  1144.  
  1145. '
  1146. Sub Hand_CheckWinner()
  1147.  
  1148.     Dim Suit1%, Suit2%, Val1%, Val2%
  1149.  
  1150.     If App_Debug Then Trace "Hand_CheckWinner"
  1151.     Game_Msg "Checking Hand..."
  1152.  
  1153.     ' retrieve cards that were played
  1154.     If Hand_PlayerTurn = 1 Then
  1155.         Hand_CardPlayer1 = Game.OnTable.Card(1)
  1156.         Hand_CardPlayer2 = Game.OnTable.Card(0)
  1157.     Else
  1158.         Hand_CardPlayer1 = Game.OnTable.Card(0)
  1159.         Hand_CardPlayer2 = Game.OnTable.Card(1)
  1160.     End If
  1161.  
  1162.  
  1163.     Suit1% = CardSuit(Hand_CardPlayer1)
  1164.     Suit2% = CardSuit(Hand_CardPlayer2)
  1165.     Val1% = CardValue(Hand_CardPlayer1)
  1166.     Val2% = CardValue(Hand_CardPlayer2)
  1167.  
  1168.  
  1169.     ' both have same suit?
  1170.     If Suit2% = Suit1% Then
  1171.         
  1172.         ' if so, higher card wins
  1173.         ' must first shift 3 and ace to higher values
  1174.         If Val1% = 3 Then Val1% = 14
  1175.         If Val2% = 3 Then Val2% = 14
  1176.  
  1177.         If Val1% = 1 Then Val1% = 15
  1178.         If Val2% = 1 Then Val2% = 15
  1179.         
  1180.         If Val1% > Val2% Then
  1181.             Hand_Winner = 1
  1182.         Else
  1183.             Hand_Winner = 2
  1184.         End If
  1185.     
  1186.     ' different suits
  1187.     Else
  1188.     
  1189.         ' check vs. briscola
  1190.         If Suit1% = Game_BriscolaSuit% Then
  1191.             Hand_Winner = 1
  1192.         
  1193.         ' player 1 doesn't have briscola
  1194.         Else
  1195.             
  1196.             ' if p2 has, he wins
  1197.             If Suit2% = Game_BriscolaSuit% Then
  1198.                 Hand_Winner = 2
  1199.             
  1200.             ' otherwise, player who put card down 1st wins
  1201.             Else
  1202.                 ' Hand_PlayerTurn indicates last player, so other was 1st
  1203.                 If Hand_PlayerTurn = 1 Then
  1204.                     Hand_Winner = 2
  1205.                 Else
  1206.                     Hand_Winner = 1
  1207.                 End If
  1208.             End If
  1209.             
  1210.         End If
  1211.     End If
  1212.  
  1213.     Game_Msg Game_PlayerName(Hand_Winner) & WINS_HAND
  1214.     
  1215. End Sub
  1216.  
  1217.  
  1218. Sub Hand_Deal()
  1219.     
  1220.     If App_Debug Then Trace "Hand_Deal"
  1221.     
  1222.     If Game_IsDealer() Then
  1223.     
  1224.         Table_Disable "Dealing..."
  1225.     
  1226.         Game.Player1.Action = CARDS_ACTION_PACK
  1227.         Game.Player2.Action = CARDS_ACTION_PACK
  1228.         
  1229.         ' pick cards from deck
  1230.         If Game.Deck.NumCards > 0 Then
  1231.             
  1232.             ' give cards according to last hand results
  1233.             If Hand_Winner% = 1 Then
  1234.                 Hand_DealCard Game.Player1
  1235.                 Hand_DealCard Game.Player2
  1236.             Else
  1237.                 Hand_DealCard Game.Player2
  1238.                 Hand_DealCard Game.Player1
  1239.             End If
  1240.     
  1241.         End If
  1242.         Table_Enable
  1243.     
  1244.     End If
  1245. End Sub
  1246. '
  1247. '
  1248. Sub Hand_DealFirst()
  1249.     
  1250.     If Game.Deck.NumCards = 0 Then Exit Sub
  1251.     
  1252.     If App_Debug Then Trace "Hand_DealFirst:"
  1253.  
  1254.     If Game_IsDealer() Then
  1255.         Table_Disable "Dealing..."
  1256.         
  1257.         Hand_SwitchPlayer
  1258.     
  1259.         ' player 2 deals, player 1 gets cards first
  1260.         
  1261.         If Hand_PlayerTurn = 1 Then
  1262.             Hand_DealCard Game.Player2
  1263.             Hand_DealCard Game.Player1
  1264.             Hand_DealCard Game.Player2
  1265.             Hand_DealCard Game.Player1
  1266.             Hand_DealCard Game.Player2
  1267.             Hand_DealCard Game.Player1
  1268.         Else
  1269.             Hand_DealCard Game.Player1
  1270.             Hand_DealCard Game.Player2
  1271.             Hand_DealCard Game.Player1
  1272.             Hand_DealCard Game.Player2
  1273.             Hand_DealCard Game.Player1
  1274.             Hand_DealCard Game.Player2
  1275.         End If
  1276.     
  1277.         Game.Briscola.TopCard = Game.Deck.TopCard
  1278.             
  1279.         Table_Enable
  1280.     End If
  1281.     
  1282. End Sub
  1283.  
  1284. Sub Hand_Next()
  1285.     
  1286.     If App_Debug Then Trace "Hand_Next"
  1287.     Hand_Stash Hand_Winner    ' give cards to winner
  1288.     Game_ShowScore            '
  1289.     
  1290.     ' Game is finished when players have no more cards in hand
  1291.     ' (deck was already emptied a couple of hands ago)
  1292.     
  1293.     ' note: we use Count() and not NumCards
  1294.     ' because cards may be unpacked (yet).
  1295.     If Game.Player1.Count(0) = 0 Then       ' is it over?
  1296.         Game_Finish False
  1297.     Else
  1298.         Hand_Deal
  1299.         Hand_SetNextPlayer Hand_Winner      ' Decide next player
  1300.         Hand_Number = Hand_Number + 1       ' Count hands
  1301.         
  1302.     End If
  1303.     
  1304.                                             ' GameTimer Will no longer call us
  1305.  
  1306.     If App_Debug Then Trace "Hand_Next: done. Next player is " & Hand_PlayerTurn
  1307.  
  1308. End Sub
  1309.  
  1310. Sub Hand_Stash(PrevWinner%)
  1311.     
  1312.     If App_Debug Then Trace "Hand_Stash"
  1313.  
  1314.     If Game_IsDealer() Then
  1315.         If PrevWinner% = 1 Then
  1316.             Hand_StashCard Game.Stack1
  1317.             Hand_StashCard Game.Stack1
  1318.         Else
  1319.             Hand_StashCard Game.Stack2
  1320.             Hand_StashCard Game.Stack2
  1321.         End If
  1322.     End If
  1323.  
  1324. End Sub
  1325.  
  1326. Sub Options_Read(f As Form)
  1327.     Dim WorkDir$
  1328.     
  1329.     On Error Resume Next
  1330.     
  1331.     WorkDir$ = Profile_ReadString$(SEC_GLOBAL, KEY_WORKDIR, "")
  1332.     If WorkDir <> "" Then ChDir WorkDir
  1333.    
  1334.     Player1_Name = Profile_ReadString$(SEC_GLOBAL, "PlayerName", "")
  1335.     
  1336.     RecentFile_Read f
  1337.     
  1338.     f.OptToolBar.Checked = Profile_ReadBool("Options", "ToolBar", True)
  1339.     f.OptStatusBar.Checked = Profile_ReadBool("Options", "StatusBar", True)
  1340.     f.OptSound.Checked = Profile_ReadBool("Options", "Sound", True)
  1341.     f.OptAnimate.Checked = Profile_ReadBool("Options", "Animation", False)
  1342.  
  1343.  
  1344.     f.ToolBar.Visible = f.OptToolBar.Checked
  1345.     f.StatusLine.Visible = f.OptStatusBar.Checked
  1346.  
  1347. End Sub
  1348.  
  1349. Sub Options_Write(f As Form)
  1350.     
  1351.     RecentFile_Write f
  1352.     
  1353.     Profile_WriteString SEC_GLOBAL, KEY_WORKDIR, CurDir$
  1354.     Profile_WriteString SEC_GLOBAL, "PlayerName", Player1_Name
  1355.     
  1356.     Profile_WriteBool "Options", "ToolBar", (f.OptToolBar.Checked)
  1357.     Profile_WriteBool "Options", "StatusBar", (f.OptStatusBar.Checked)
  1358.     Profile_WriteBool "Options", "Sound", (f.OptSound.Checked)
  1359.     Profile_WriteBool "Options", "Animation", (f.OptAnimate.Checked)
  1360.  
  1361. End Sub
  1362.  
  1363. Sub Robot_PlayCard(pl As Cardpack)
  1364.     Dim idx%
  1365.     
  1366.     If App_Debug Then Trace "Robot_PlayCard"
  1367.     Table_Disable "Thinking..."
  1368.     idx% = Robot_ThinkCard(pl)
  1369.     
  1370.     If idx% <> CARD_NONE Then
  1371.         
  1372.         ' animate card before removing
  1373.         pl.Selected(idx%) = True
  1374.         Sleep 0.5
  1375.         
  1376.         ' play that card
  1377.         Hand_PlayCard pl, idx%
  1378.  
  1379.     End If
  1380.     
  1381.     Table_Enable
  1382.  
  1383. End Sub
  1384.  
  1385. Sub Sleep(s As Single)
  1386.  
  1387.     Dim start
  1388.     
  1389.     start = Timer
  1390.     Do
  1391.         'DoEvents
  1392.     Loop Until Timer > start + s
  1393.     
  1394. End Sub
  1395.  
  1396. Sub Table_Clear()
  1397.     
  1398.     Table_Disable "Preparing table..."
  1399.     
  1400.     Game.Stack1.NumCards = 0
  1401.     Game.Stack2.NumCards = 0
  1402.     Game.Player1.NumCards = 0
  1403.     Game.Player2.NumCards = 0
  1404.     Game.Deck.NumCards = 40
  1405.     Game.OnTable.NumCards = 0
  1406.     Game.Briscola.NumCards = 0
  1407.     
  1408.     Game.Deck.Shuffle
  1409.     Game_ShowScore
  1410.     Table_Enable
  1411.     
  1412. End Sub
  1413.  
  1414. Sub Table_Disable(Msg$)
  1415.         
  1416.     ' Avoid nesting
  1417.     If Game.Enabled = True Then
  1418.         Game_Msg Msg$
  1419.         Screen.MousePointer = HOURGLASS
  1420.         Game.Enabled = False
  1421.     End If
  1422.  
  1423. End Sub
  1424.  
  1425. Sub Table_Enable()
  1426.        
  1427.     ' Avoid nesting
  1428.     If Not Game.Enabled Then
  1429.         Game.Enabled = True
  1430.         'Game_Msg "Ready"
  1431.         Screen.MousePointer = Default
  1432.     End If
  1433. End Sub
  1434.  
  1435. Sub Trace(s$)
  1436.     
  1437.     If App_Debug Then
  1438.         TraceWin.LogBox.AddItem s$
  1439.         If TraceWin.LogBox.ListCount > 100 Then TraceWin.LogBox.RemoveItem 0
  1440.         TraceWin.LogBox.TopIndex = TraceWin.LogBox.ListCount - 1
  1441.         Debug.Print s$
  1442.     End If
  1443.  
  1444. End Sub
  1445.  
  1446. Sub TraceClear()
  1447.     TraceWin.LogBox.Clear
  1448. End Sub
  1449.  
  1450. Sub TraceMode(Mode%)
  1451.     If Mode% Then
  1452.         App_Debug = True
  1453.         TraceWin.Show
  1454.     Else
  1455.         App_Debug = False
  1456.         TraceWin.Hide
  1457.     End If
  1458. End Sub
  1459.  
  1460.